Ext.define('DCApp.view.img.ListController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.imglist',

    getSelectedItem: function(){
        return this.getView().getSelectionModel().getSelection()[0] || false;
    },
    onOpenImg: function() {
    	var sel = this.getSelectedItem();
    	if(!sel)
    		return;
    	this.fireViewEvent('viewimg', this.getView(), sel);
    },

    
    onImgDblClick: function(view, rec) {
    	this.fireViewEvent('viewimg', this.getView(), rec);
    },
    
    onRemove: function() {
        //this.getView().getStore().load();    	
    	var vw = this.getView();
    	if(vw.getXType()=='imgpanel'){
    		var dv = vw.down('[xtype="imgview"]');
    		var sels = dv.getSelectionModel().getSelection();
    		if(sels.length==0){
    			Ext.MessageBox.alert('操作提示', '请先选择待删除的影像',
    			null, this);
    			return;
    		}else{
    			Ext.MessageBox.confirm('确认删除', '您确定要删除选中的['+sels.length+']项?',
    			function(btn, text){
    				if(btn!='yes')
    					return false;
    	    		dv.getStore().remove(sels);    				
    			}, this);
    		}
    		console.log(dv);
    	}
    },
    onSetMode:function(btn){
    	var vw = this.getView();
    	var dv = vw.down('[xtype="imgview"]');
    	dv.showTip=btn.text=='详细';
    },
    onRel:function(btn){
    	var vw = this.getView();
    	var dv = vw.down('[xtype="imgview"]');
    	var ds = dv.getStore();
    	ds.on('datachanged',function(d,opt){
    		//console.log(d);
    		dv.refresh();
    	});
    	var data = this.getViewModel().getData();
        var win = new Ext.window.Window({
        	width:500,
        	height:300,
        	//title:'相关影像',
        	//header:false,
        	layout:'fit',
        	modal:true,
        	viewModel: this.getViewModel(),
        	items:[{
        		 fieldName: 'imageName',
        		 xtype: 'multiselector',
        		 title:'选择影像',
        		 //bind:dv.getBind(),
        		 store:ds,
                 search: {
                	 field: 'imageName',
                     store: {
                         model: 'Image'
                     }
                 }
        		}
        	],   
        	plain: true,
            headerPosition: 'bottom'
        });
        win.show();    	
    }

});
